<template>
  <div class="main-scroll">
    <cheader :title="title"></cheader>
    <el-card class="box-card">
      <!-- <div class="title-text">数据筛选</div> -->
      <div style="padding: 10px" class="c-filter">
        <el-form
          :inline="true"
          :model="filterForm"
          class="demo-form-inline"
          label-width="70px"
        >
          <el-form-item label="输入查询">
            <el-input
              v-model="filterForm.emplName"
              placeholder="员工姓名"
            ></el-input>
          </el-form-item>

          <el-form-item label="部门">
            <el-input
              v-model="filterForm.deptTypeName1"
              placeholder="部门"
            ></el-input>
          </el-form-item>

          <el-form-item label="二级部门">
            <el-input
              v-model="filterForm.deptTypeName2"
              placeholder="二级部门"
            ></el-input>
          </el-form-item>

          <el-form-item label="班组">
            <el-input
              v-model="filterForm.deptTypeName5"
              placeholder="班组"
            ></el-input>
          </el-form-item>

          <el-form-item label="日期" prop="matterDate">
            <el-date-picker
              v-model="filterForm.matterDate"
              type="daterange"
              range-separator="至"
              start-placeholder="起始日期"
              end-placeholder="截止日期"
              value-format="yyyy-MM-dd"
              @change="changeDate"
            >
            </el-date-picker>
          </el-form-item>
          <el-row>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="query"
                >查询</el-button
              >
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="reset">清除查询条件</el-button>
            </el-form-item>
          </el-row>
        </el-form>
      </div>
    </el-card>
    <el-card>
      <!-- <div class="main-seting">
        <div> -->
      <!-- <div class="title-text">数据列表</div> -->
      <el-button
        v-auth="'C09002'"
        style="
          float: right;
          margin-right: 20px;
          margin-bottom: 20px;
          margin-top: 20px;
        "
        icon="el-icon-download"
        @click="exportExcel"
        >导出</el-button
      >
      <el-button
        v-auth="'C09001'"
        type="primary"
        style="
          float: right;
          margin-right: 20px;
          margin-bottom: 20px;
          margin-top: 20px;
        "
        @click="dialogVisible = true"
        icon="el-icon-plus"
        >添加</el-button
      >
      <div style="margin: 20px; min-height: 55vh">
        <el-table
          :data="matterList"
          border
          style="width: 100%"
          :header-cell-style="{ background: '#F6F7FB' }"
        >
          <el-table-column
            type="index"
            :index="indexAdd"
            label="序号"
            width="50"
          >
          </el-table-column>
          <el-table-column label="年份">
            <template slot-scope="scope">
              <p>{{ scope.row.matterDate | formatDate('yyyy') }}</p>
            </template>
          </el-table-column>
          <el-table-column label="一级部门">
            <template slot-scope="scope">
              <p>{{ scope.row.deptLevelName1 }}</p>
            </template>
          </el-table-column>
          <el-table-column label="二级部门">
            <template slot-scope="scope">
              <p>{{ scope.row.deptLevelName2 }}</p>
            </template>
          </el-table-column>
          <el-table-column label="班组">
            <template slot-scope="scope">
              <p>{{ scope.row.deptLevelName5 }}</p>
            </template>
          </el-table-column>
          <el-table-column label="姓名">
            <template slot-scope="scope">
              <p>{{ scope.row.creatorName }}</p>
            </template>
          </el-table-column>
          <el-table-column label="日期">
            <template slot-scope="scope">
              <p>{{ scope.row.matterDate | formatDate('yyyy-MM-dd') }}</p>
            </template>
          </el-table-column>
          <el-table-column label="事项说明">
            <template slot-scope="scope">
              <p>{{ scope.row.description }}</p>
            </template>
          </el-table-column>
          <el-table-column label="备注">
            <template slot-scope="scope">
              <p>{{ scope.row.remark }}</p>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <el-pagination
        v-if="isUpdate"
        background
        layout="prev, pager, next"
        :page-size="pageSize"
        :total="total"
        :hide-on-single-page="total < 10"
        @current-change="currentChange"
        style="margin-left: 25%"
      >
      </el-pagination>
      <!-- </div>
      </div> -->
    </el-card>

    <el-dialog
      title="添加"
      :visible.sync="dialogVisible"
      @close="cancel"
      width="50%"
    >
      <el-form
        ref="createForm"
        :model="createForm"
        :rules="rules"
        label-width="200px"
      >
        <el-form-item label="日期:" prop="matterDate">
          <el-date-picker
            v-model="createForm.matterDate"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
            @change="changeDate2"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="事项说明:" prop="description">
          <el-input
            v-model="createForm.description"
            type="textarea"
            :rows="4"
            placeholder="请填写"
          ></el-input>
        </el-form-item>

        <el-form-item label="备注:" :show-overflow-tooltip="true">
          <el-input v-model="createForm.remark" placeholder="请填写"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="createMatter">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import cheader from '@/components/header.vue';
import { createMatter, matterList } from '@/api/personal-files';
import { exportMethod } from '@/utils/utils';

export default {
  components: {
    cheader,
  },
  data() {
    return {
      isUpdate: true,
      title: '年度重大事项说明',
      value1: '',
      form: '',
      filterForm: {
        emplName: '',
        deptTypeName1: '',
        deptTypeName2: '',
        deptTypeName5: '',
        matterDate: '',
      },
      createForm: {
        matterDate: '',
        description: '',
        remark: '',
      },
      rules: {
        description: [
          { required: true, message: '请填写事项说明', trigger: 'blur' },
        ],
        matterDate: [
          { required: true, message: '请选择日期', trigger: 'change' },
        ],
      },
      pageNo: 1, // 分页页码
      pageSize: 10, // 每页条数
      total: 0,
      matterList: [],
      dialogVisible: false,
    };
  },
  created() {
    this.getMatterList();
  },
  methods: {
    exportExcel() {
      const data = {
        deptTypeName1: this.filterForm.deptTypeName1,
        deptTypeName2: this.filterForm.deptTypeName2,
        deptTypeName5: this.filterForm.deptTypeName5,
        emplName: this.filterForm.emplName,
        matterDateEnd: this.filterForm.matterDate[1],
        matterDateStart: this.filterForm.matterDate[0],
        pageNo: this.pageNo,
        pageSize: 5000,
      };
      exportMethod('matter', data, '年度重大事项说明');
    },
    changeDate(date) {
      this.filterForm.matterDate = date;
    },
    cancel() {
      this.dialogVisible = false;
      this.$refs.createForm.resetFields();
      this.createForm.remark = '';
    },
    changeDate2(date) {
      this.createForm.matterDate = date;
    },
    createMatter() {
      this.$refs.createForm.validate(async (valid) => {
        if (valid) {
          const res = await createMatter({
            matterDate: this.createForm.matterDate,
            description: this.createForm.description,
            remark: this.createForm.remark,
          });
          if (res.code == 200) {
            this.$message({
              message: '创建成功',
              type: 'success',
            });
            this.dialogVisible = false;
            this.getMatterList();
          }
        } else {
          return false;
        }
      });
    },
    query() {
      this.pageNo = 1;
      this.isUpdate = false;
      this.getMatterList();
    },
    reset() {
      this.filterForm.emplName = '';
      this.filterForm.deptTypeName1 = '';
      this.filterForm.deptTypeName2 = '';
      this.filterForm.deptTypeName5 = '';
      this.filterForm.matterDate = '';
    },
    currentChange(pageNo) {
      this.pageNo = pageNo;
      this.getMatterList();
    },
    // 序号-页面切换递增
    indexAdd(index) {
      return index + 1 + (this.pageNo - 1) * this.pageSize;
    },
    async getMatterList() {
      const res = await matterList({
        deptTypeName1: this.filterForm.deptTypeName1,
        deptTypeName2: this.filterForm.deptTypeName2,
        deptTypeName5: this.filterForm.deptTypeName5,
        emplName: this.filterForm.emplName,
        matterDateEnd: this.filterForm.matterDate[1],
        matterDateStart: this.filterForm.matterDate[0],
        pageNo: this.pageNo,
        pageSize: this.pageSize,
      });
      if (res.code == 200) {
        this.isUpdate = false;
        this.matterList = res.data.list;
        this.total = res.data.total;
      }
      console.log('this.evaluateList', this.evaluateList);
    },
    onSubmit() {
      console.log('submit!');
    },
  },
};
</script>

<style lang="scss" scoped>
.c-main-make {
  margin-left: 35px;
  height: 300px;
  background: #fff;
  margin-right: 35px;
  margin-bottom: 35px;
  position: relative;
  overflow: hidden;
  border: 1px #dcdee0 solid;
}
.main-seting {
  width: 100%;
}
.c-main-show {
  margin-left: 35px;
  min-height: 700px;
  background: #fff;
  margin-right: 35px;
  margin-bottom: 35px;
  position: relative;
  // overflow: hidden;
  border: 1px #dcdee0 solid;
}
.title-text {
  width: 100%;
  height: 50px;
  border-bottom: 1px #dcdee0 solid;
  font-family: '微软雅黑 Bold', '微软雅黑 Regular', 微软雅黑, sans-serif;
  font-weight: 700;
  color: #666666;
  line-height: 50px;
  padding-left: 25px;
}
.main-scroll {
  height: 1000px;
  // overflow-y: scroll;
}
.pagination {
  display: flex;
  justify-content: end;
}
.box-card {
  margin-bottom: 20px;
}
.el-input {
  width: 250px;
}
.el-select {
  width: 250px;
}
.el-textarea {
  width: 400px;
}
</style>
